<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model
        layout="horizontal"
        ref="form"
        :label-col="labelCol"
        :wrapper-col="wrapperCol"
        :model="inWareHouseData"
        class="form_model"
      >
        <a-form-item label="分类名">
          <a-tree-select
            v-model="inWareHouseData.category_name"
            :replace-fields="{ children: 'children', title: 'title', key: 'code', value: 'code' }"
            style="width: 100%"
            :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
            :tree-data="categoryArr"
            placeholder="请输入分类名"
            @change="selectCategory"
            allowClear
          >
          </a-tree-select>
        </a-form-item>
        <a-form-item label="仓库" has-feedback>
          <a-select placeholder="请选择仓库" @change="selectWareHouse" allowClear v-model="inWareHouseData.warehouseId">
            <a-select-option :value="item.id" v-for="item in wareHouseArr" :key="item.id">
              {{ item.name }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="货架号">
          <a-input placeholder="请输入货架号" v-model="inWareHouseData.goodsShelfNo" />
        </a-form-item>
        <a-form-item label="货架层数">
          <a-input placeholder="请输入货架层数" v-model="inWareHouseData.shelfLayerNo" />
        </a-form-item>
        <a-form-item label="货架格数">
          <a-input placeholder="请输入货架格数" v-model="inWareHouseData.shelfGridNo" />
        </a-form-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
// import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction, httpAction, postAction } from '@api/manage'

export default {
  name: 'InWareHouseModal',
  // mixins: [JeecgListMixin],
  data() {
    return {
      treeValue: '',
      treeExpandedKeys: [],
      //仓库数据
      wareHouseArr: [],
      //分类数据
      categoryArr: [],
      inWareHouseData: {
        warehouseId: '',
        goodsShelfNo: '',
        shelfGridNo: '',
        category_name: '',
        category_code: '',
        itemId: '',
        shelfLayerNo: ''
      },
      title: '操作',
      visible: false,
      model: {},
      layout: {
        labelCol: { span: 3 },
        wrapperCol: { span: 14 }
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      url: {
        add: '/baseInfo/materialCtrl/add'
        // edit: "/test/jeecgDemo/edit",
      }
    }
  },
  //入库的工装信息
  props: ['params'],
  created() {},
  methods: {
    add() {
      this.edit({})
      this.wareHouseArr = []
      this.categoryArr = []
      this.inWareHouseData = {}
      getAction('/warehouseCtrl/getWarehouseList').then(res => {
        res.result.records.map(item => {
          this.wareHouseArr.push(item)
        })
      })
      getAction('/sys/category/loadTreeRoot', { async: false, pcode: '' }).then(res => {
        res.result.map(item => {
          this.categoryArr.push(item)
        })
      })
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    close() {
      this.$refs.form.resetFields()
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.inWareHouseData.itemId = this.params.id
      postAction('/fixtureToolCtrl/updateFixInWarehouse', this.inWareHouseData)
        .then(res => {
          // console.log('入库响应', res)
          if (res.success) {
            this.$message.success(res.message)
            this.$emit('ok')
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.confirmLoading = false
          this.close()
        })
    },
    handleCancel() {
      this.close()
    },
    selectWareHouse(id) {
      this.inWareHouseData.warehouseId = id
    },
    selectCategory(id, name) {
      this.inWareHouseData.category_code = id
      this.inWareHouseData.category_name = name[0]
    }
  }
}
</script>

<style scoped>
.form_model {
  display: flex;
  flex-wrap: wrap;
}
.ant-form-item {
  width: 50%;
}

.ant-modal {
  margin-top: 100px !important;
}

.ant-modal-content {
  margin-top: 100px !important;
}
</style>
